package com;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.api.gbhg.huangwm.BxActionV2.WebApi;
import com.api.gbhg.huangwm.dao.BudgetManagementDownDao;
import com.api.gbhg.huangwm.dao.ProjectOperationDao;
import com.api.gbhg.huangwm.dao.YuSuanTiaoZhengDao;
import com.api.gbhg.huangwm.web.ProjectOperationApi;
import com.api.gbhg.liuwenbo.api.BudgetSectionIncomeApi;
import com.api.gbhg.liuwenbo.version3.api.*;
import com.api.gbhg.wangc.api.BudgetManagementApi;
import com.customization.commons.LogTool;
import com.engine.common.util.ParamUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.junit.Before;
import org.junit.Test;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
import weaver.general.BaseBean;
import weaver.general.GCONST;
import weaver.general.Util;
import weaver.hrm.User;

import javax.ws.rs.core.Response;
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author Huangwm
 * @Date 2022-04-20
 * @Version 1.0
 * @Description TODO
 **/
public class Debug{
    private LogTool log = new LogTool("/log/gbhg/huangwm/Debug",false);

    public static void main(String[] args){

        String rootPath = "D:\\WEAVER\\ecology\\";
        GCONST.setRootPath(rootPath);
        GCONST.setServerName("ecology");

        BudgetManagementApi api = new BudgetManagementApi();
        Map<String, Object> param = new HashMap<>();
        param.put("year","2023");
        param.put("proName","珠江口反走私反偷渡专项经费");
        param.put("unitName","");
        param.put("startDate","");
        param.put("endDate","");
        param.put("pageNum",1);
        param.put("pageSize",10);
        param.put("sbdw","");
        param.put("dlhsdw","");
        param.put("userid","13939");
        param.put("queryDate","2023-11-02");
        down(param);

        ProjectOperationApi api2 = new ProjectOperationApi();
        //api2.downProjectAccountListV2(param);

//        IcomeBudgetExpendApi api3 = new IcomeBudgetExpendApi();
//        param.put("nf","2022");
//        param.put("ysly","上年");
//        //System.err.println(api3.getIcomeBudgetExpendList(param));
//
//        FinancialInStatApi api4 = new FinancialInStatApi();
//        //System.err.println(api4.getFinancialInStatList(param));
//
//        BudgetSectionIncomeApi api5 = new BudgetSectionIncomeApi();
//        param.put("dw","1");
//        param.put("jz","yqndsjjzje");
//        //System.err.println(JSONObject.toJSONString(api5.getFczbksrData(param)));
//
//        NoFinancialInStatApi api6 = new NoFinancialInStatApi();
//        //System.err.println(api6.getNoFinancialInStatList(param));
//
//        YuSuanTiaoZhengDao dao = new YuSuanTiaoZhengDao();
//        //System.err.println(dao.getZyczbksrName("28_27"));
//
//        WebApi api7 = new WebApi();
//        Map<String, Object> param7 = new HashMap<>();
//        param7.put("userId","13939");
//        param7.put("rowIndex","0");
//        param7.put("wfid","332");
//        param7.put("requestid","796620");
//        param7.put("ysxm","593843");
//        param7.put("bmjjzcfl","30231");
//        param7.put("zfjjzcfl","50208");
//        param7.put("sqbxje",31837.02);
//        param7.put("cxje",0);
//        param7.put("jbbm",272);
//        param7.put("key",386);
//        //System.err.println(api7.releaseJingFei(param7));
//        //System.err.println(api7.reduceJingFei(param7));
//
//        param.put("ysnd","2022");
//        List<Map<String, Object>> list1 = new ArrayList<>();
//        List<Map<String, Object>> list2 = new ArrayList<>();
//        ProjectOperationDao dao1 = new ProjectOperationDao();
        //list1 = dao1.getProjectList2Zyczbksr1(param);
//        list2 = dao1.getProjectList2Zyczbksr2(param);
        //System.err.println(JSONObject.toJSONString(list1));
//        System.err.println(JSONObject.toJSONString(list2));
//        down(param);

//        RtExpensesPayApi rt = new RtExpensesPayApi();
//        Map map = new HashMap();
//        map.put("bmysjjfl","");
//        map.put("dfczbkxm","");
//        map.put("fzysrfl","");
//        map.put("jbbm","");
//        map.put("pageNumber",1);
//        map.put("pageSize","10");
//        map.put("srlx","0");
//        map.put("ysly","");
//        map.put("zfysjjfl","");
//        map.put("dygnkmbid","28_14");
//        map.put("year",2022);
//        System.err.println(rt.getREPList(map));
    }

    public static void down(Map<String,Object> requestParam){
        //项目台账导出
        BudgetManagementDownDao downDao = new BudgetManagementDownDao();
        YuSuanTiaoZhengDao tiaoZhengDao = new YuSuanTiaoZhengDao();
        HSSFCellStyle titleStyle = null;//大标题行字体
        HSSFCellStyle cellStyle = null;//标题行字体
        HSSFCellStyle dataRowStyle = null;//数据行字体
        HSSFCellStyle dataRowStyle_o1 = null;//数据行其他字体
        HSSFCellStyle l3RowStyle = null;//说明所在行

        Calendar calendar = Calendar.getInstance();
        //int year = calendar.get(Calendar.YEAR);//当前年份

        try {

            String proName = (String) requestParam.getOrDefault("proName","");
            String unitName = (String) requestParam.getOrDefault("unitName","");//使用单位
            String startDate = (String) requestParam.getOrDefault("startDate","");
            String endDate = (String) requestParam.getOrDefault("endDate","");
            Integer pageNum = Util.getIntValue(requestParam.getOrDefault("pageNum","1").toString(),1);
            Integer pageSize = Util.getIntValue(requestParam.getOrDefault("pageSize","10").toString(),10);
            String sbdw = (String) requestParam.getOrDefault("sbdw","");//申报单位
            String year = (String) requestParam.getOrDefault("year","");//
            String pdlhsdw = (String) requestParam.getOrDefault("dlhsdw","");//

            String edate = requestParam.get("queryDate").toString();


            HSSFWorkbook workbook = new HSSFWorkbook();//创建表格
            HSSFSheet sheet = workbook.createSheet("各单位预算执行情况");//在表格中创建一个标签
            //sheet.protectSheet("123456");//加锁
            //设置默认的列宽度
            sheet.setDefaultColumnWidth(9);
            sheet.setColumnWidth(0,250*10);
            sheet.setColumnWidth(1,450*10);
            sheet.setColumnWidth(2,450*10);
            sheet.setColumnWidth(3,500*10);
            sheet.setColumnWidth(4,1400*10);
            sheet.setColumnWidth(5,450*10);
            sheet.setColumnWidth(6,450*10);
            sheet.setColumnWidth(7,450*10);
            sheet.setColumnWidth(8,450*10);
            sheet.setColumnWidth(9,1400*10);
            sheet.setColumnWidth(10,550*10);
            sheet.setColumnWidth(11,550*10);
            /*-------------------------大标题行-------------------------*/
            //定义单元格风格
            titleStyle = workbook.createCellStyle();
            //设置水平居中
            titleStyle.setAlignment(HorizontalAlignment.CENTER);
            //设置垂直居中
            titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            //设置字体
            HSSFFont font_title = workbook.createFont();
            //设置字体名称
            font_title.setFontName("方正仿宋_GBK");
            //设置字号
            font_title.setFontHeightInPoints((short)14);
            //设置是否为斜体
            font_title.setItalic(false);
            //设置是否加粗
            font_title.setBold(true);
            //设置字体颜色
            font_title.setColor(IndexedColors.BLACK.index);
            //设置行的高度
            titleStyle.setFont(font_title);
            titleStyle.setLocked(true);
            /*--------------------------大标题行-------------------------*/
            HSSFRow row1 = sheet.createRow(0);

            HSSFRow row2 = sheet.createRow(1);//大标题所在行
            HSSFCell cell_row2 = row2.createCell(0);
            cell_row2.setCellStyle(titleStyle);
            cell_row2.setCellValue(year+"各单位预算项目执行情况");
            CellRangeAddress rangeHeard = new CellRangeAddress(1, 1, 0, 7);
            sheet.addMergedRegion(rangeHeard);
            row2.setHeightInPoints(32);

            /*-------------------------小标题行-------------------------*/
            //定义单元格风格
            cellStyle = workbook.createCellStyle();
            //设置水平居中
            cellStyle.setAlignment(HorizontalAlignment.CENTER);
            //设置垂直居中
            cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            cellStyle.setLocked(true);//锁定行
            //设置字体
            HSSFFont font = workbook.createFont();
            //设置字体名称
            font.setFontName("方正仿宋_GBK");
            //设置字号
            font.setFontHeightInPoints((short)12);
            //设置是否为斜体
            font.setItalic(false);
            //设置是否加粗
            font.setBold(true);
            //设置字体颜色
            font.setColor(IndexedColors.BLACK.index);
            //设置行的高度
            cellStyle.setFont(font);
            /*--------------------------小标题行-------------------------*/
            HSSFRow row3 = sheet.createRow(2);//创建第三行作为标题行
            HSSFCell cell_row3_0 = row3.createCell(0);
            cell_row3_0.setCellStyle(cellStyle);
            cell_row3_0.setCellValue("序号");
            HSSFCell cell_row3_1 = row3.createCell(1);
            cell_row3_1.setCellStyle(cellStyle);
            cell_row3_1.setCellValue("年份");
            HSSFCell cell_row3_2 = row3.createCell(2);
            cell_row3_2.setCellStyle(cellStyle);
            cell_row3_2.setCellValue("申报单位");
            HSSFCell cell_row3_3 = row3.createCell(3);
            cell_row3_3.setCellStyle(cellStyle);
            cell_row3_3.setCellValue("独立核算单位");
            HSSFCell cell_row3_4 = row3.createCell(4);
            cell_row3_4.setCellStyle(cellStyle);
            cell_row3_4.setCellValue("项目名称");
            HSSFCell cell_row3_5 = row3.createCell(5);
            cell_row3_5.setCellStyle(cellStyle);
            cell_row3_5.setCellValue("预算核批数(万元)");
            HSSFCell cell_row3_6 = row3.createCell(6);
            cell_row3_6.setCellStyle(cellStyle);
            cell_row3_6.setCellValue("项目支出数(万元)");
            HSSFCell cell_row3_7 = row3.createCell(7);
            cell_row3_7.setCellStyle(cellStyle);
            cell_row3_7.setCellValue("项目冻结数(万元)");
            HSSFCell cell_row3_8 = row3.createCell(8);
            cell_row3_8.setCellStyle(cellStyle);
            cell_row3_8.setCellValue("执行率(万元)");
            HSSFCell cell_row3_9 = row3.createCell(9);
            cell_row3_9.setCellStyle(cellStyle);
            cell_row3_9.setCellValue("核批渠道");
            HSSFCell cell_row3_10 = row3.createCell(10);
            cell_row3_10.setCellStyle(cellStyle);
            cell_row3_10.setCellValue("渠道核批金额(元)");
            HSSFCell cell_row3_111 = row3.createCell(11);
            cell_row3_111.setCellStyle(cellStyle);
            cell_row3_111.setCellValue("渠道支出金额(元)");
            row3.setHeightInPoints(26);

            /*-------------------------数据行--------------------------*/
            //定义单元格风格
            dataRowStyle = workbook.createCellStyle();
            //设置水平居中
            dataRowStyle.setAlignment(HorizontalAlignment.CENTER);
            //设置垂直居中
            dataRowStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            //设置字体
            HSSFFont font_datarow = workbook.createFont();
            //设置字体名称
            font_datarow.setFontName("方正仿宋_GBK");
            //设置字号
            font_datarow.setFontHeightInPoints((short)12);
            //设置是否为斜体
            font_datarow.setItalic(false);
            //设置是否加粗
            font_datarow.setBold(false);
            //设置字体颜色
            font_datarow.setColor(IndexedColors.BLACK.index);
            //设置行的高度
            dataRowStyle.setFont(font_datarow);
            /*-------------------------数据行--------------------------*/
            /*-------------------------数据行靠左--------------------------*/
            //定义单元格风格
            dataRowStyle_o1 = workbook.createCellStyle();
            //设置水平居中
            dataRowStyle_o1.setAlignment(HorizontalAlignment.LEFT);
            //设置垂直居中
            dataRowStyle_o1.setVerticalAlignment(VerticalAlignment.CENTER);
            //设置字体
            HSSFFont font_datarow_ol = workbook.createFont();
            //设置字体名称
            font_datarow_ol.setFontName("方正仿宋_GBK");
            //设置字号
            font_datarow_ol.setFontHeightInPoints((short)12);
            //设置是否为斜体
            font_datarow_ol.setItalic(false);
            //设置是否加粗
            font_datarow_ol.setBold(false);
            //设置字体颜色
            font_datarow_ol.setColor(IndexedColors.BLACK.index);
            //设置行的高度
            dataRowStyle_o1.setFont(font_datarow_ol);
            /*-------------------------数据行靠左--------------------------*/
            System.err.println("经费版本参数 "+JSONObject.toJSONString(requestParam));
            // 查询数据
            RecordSetTrans mainTable = downDao.getFundingVersion(proName, unitName, startDate, endDate, pageNum, pageSize, requestParam.get("userid").toString(), sbdw,year,pdlhsdw);
            // 查询总数
            int total = downDao.getMainTableCount(proName, unitName, startDate, endDate, requestParam.get("userid").toString(), sbdw,year,pdlhsdw);

            Map<String, Object>[] map = new HashMap[mainTable.getArray().size()];
            int i = 0;
            int j = 1; //序号
            RecordSet rs1 = new RecordSet();
            RecordSet rs2 = new RecordSet();
            RecordSet rs3 = new RecordSet();
            RecordSet rs4 = new RecordSet();

            while (mainTable.next()) {
                map[i] = new HashMap<>();
                map[i].put("lcid", mainTable.getInt("lcid"));//流程id
                map[i].put("lcbj", mainTable.getString("lcbj"));//流程标记
                map[i].put("lcjlsqjlid", mainTable.getInt("lcjlsqjlid"));//流程记录申请记录id
                map[i].put("lczt", mainTable.getString("lczt"));//流程状态
                map[i].put("lcztz", mainTable.getString("lcztz"));//流程状态值
                map[i].put("sfky", mainTable.getString("sfky"));//是否可用
                map[i].put("sbdw", downDao.getSubCompanyNameById(mainTable.getString("sbdw")));//申报单位
                map[i].put("ysnd", mainTable.getString("ysnd"));//预算年度
                String sfwzjxm = mainTable.getString("sfwzjxm");
                map[i].put("sfwzjxm", (sfwzjxm.isEmpty() || sfwzjxm.equals("0")?"否":"是"));//是否为追加项目
                map[i].put("xmmin", mainTable.getString("xmmin")+"(是否追加:"+(sfwzjxm.isEmpty() || sfwzjxm.equals("0")?"否":"是")+")");//项目名称
                map[i].put("sfzdxm", mainTable.getString("sfzdxm"));//是否重点项目

                //负责人
                if ("1".equals(mainTable.getString("fzr"))) {
                    map[i].put("fzr", "系统管理员");
                } else {
                    if (mainTable.getString("fzr").matches("[0-9]+")) {
                        map[i].put("fzr", downDao.getUserNameById(mainTable.getString("fzr")));
                    } else {
                        map[i].put("fzr", mainTable.getString("fzr"));
                    }
                }
                //经办人
                if ("1".equals(mainTable.getString("jbr"))) {
                    map[i].put("jbr", "系统管理员");
                } else {
                    map[i].put("jbr", downDao.getUserNameById(mainTable.getString("jbr")));
                }
                String czbk = mainTable.getString("czbk");
                String jzje = mainTable.getString("jzje");
                if (StringUtils.isBlank(czbk)) {
                    czbk = "0.00";
                }
                if (StringUtils.isBlank(jzje)) {
                    jzje = "0.00";
                }
                String dlhsdw = mainTable.getString("dlhsdw");//独立核算单位
                if(dlhsdw.isEmpty()){
                    map[i].put("dlhsdw", "NULL");
                }else{
                    map[i].put("dlhsdw", downDao.getSubCompanyNameById(dlhsdw));
                }

                map[i].put("czbk", Double.valueOf(czbk) > 0 ? BigDecimal.valueOf(mainTable.getDouble("czbk")).setScale(2, RoundingMode.DOWN) : "0.00");//财政拨款
                map[i].put("jzje", Double.valueOf(jzje) > 0 ? BigDecimal.valueOf(mainTable.getDouble("jzje")).setScale(2, RoundingMode.DOWN) : "0.00");//结转金额
                map[i].put("bz", mainTable.getString("bz"));//备注
                map[i].put("sbks", downDao.getDepartmentNameById(mainTable.getString("sbks")));//申报科室
                map[i].put("lxdh", mainTable.getString("lxdh"));//联系电话
                map[i].put("gkdw", mainTable.getString("gkdw"));//归口单位
                map[i].put("sydw", mainTable.getString("sydw"));//使用单位

                String requestId = mainTable.getString("requestId");
                //logger.info("项目台账已归档请求id--------"+requestId);
                RecordSetTrans sub = downDao.getFundsAmount(requestId);
                if (sub.next()) {
                    RecordSetTrans subTable = downDao.getFundsAmount(requestId);
                    BigDecimal bai = new BigDecimal("100");
                    BigDecimal ze = new BigDecimal(0);
                    BigDecimal syed = new BigDecimal(0);
                    BigDecimal djed = new BigDecimal(0);
                    BigDecimal yyed = new BigDecimal(0);
                    BigDecimal yszxl = new BigDecimal(0);
                    BigDecimal yszje = new BigDecimal(0);
                    BigDecimal wan = new BigDecimal("10000");
                    String getYbx = "SELECT ISNULL(SUM(d1.tybxje-ISNULL(d1.cxje,0)),0) as ybx FROM dbo.uf_bxjl_kj_dt1 d1 \n" +
                            "LEFT JOIN uf_bxjl_kj d ON d1.lcid=d.lcid\n" +
                            "LEFT JOIN dbo.workflow_requestbase wr ON d1.lcid=wr.requestid\n" +
                            "WHERE ysxm=" + requestId + "  AND d.shrq<='"+edate+"' ";//6月30号前的执行率
                    rs1.execute(getYbx);
                    rs1.next();
//                  String getDj = "SELECT ISNULL(SUM(d1.tybxje-d1.cxje),0) as dj FROM dbo.uf_bxjl_kj_dt1 d1 \n" +
//                            "LEFT JOIN uf_bxjl_kj d ON d1.lcid=d.lcid\n" +
//                            "LEFT JOIN dbo.workflow_requestbase wr ON d1.lcid=wr.requestid\n" +
//                            "LEFT JOIN workflow_base wb ON wr.workflowid=wb.id\n" +
//                            "WHERE ysxm="+requestId+" AND wr.currentnodetype in(1,2)";
                    String getDj = "SELECT ISNULL(SUM(t.sqbxje-isnull(cxje,0)),0) as dj FROM (\n" +
                            "\tSELECT wr.requestid,jl.lclx,jl.sqbxje,jl.cxje FROM dbo.uf_bxsjjl  jl LEFT JOIN workflow_requestbase wr ON jl.lcid=wr.requestid\n" +
                            "\tWHERE ysxm=" + requestId + " AND wr.currentnodetype IN (1,2)\n" +
                            ")t WHERE t.requestid IS NOT NULL  AND t.requestid NOT IN (SELECT d1.lcid FROM dbo.uf_bxjl_kj_dt1 d1 \n" +
                            "LEFT JOIN uf_bxjl_kj d ON d1.lcid=d.lcid\n" +
                            "WHERE   d.shrq<='"+endDate+"' AND ysxm="+requestId+" ) ";
                    rs2.execute(getDj);
                    rs2.next();
                    //预算总金额
                    yszje = new BigDecimal(mainTable.getDouble("yszje"));
                    yszje = yszje.divide(wan, 4, BigDecimal.ROUND_HALF_UP);
                    map[i].put("yszje", yszje);
                    while (subTable.next()) {
                        ze = ze.add(new BigDecimal(subTable.getString("ze")));
                        //syed = syed.add(new BigDecimal(subTable.getString("syed")));
                        //djed = djed.add(new BigDecimal(subTable.getString("dj")));
                    }
                    //BigDecimal yyed1 = ze.subtract(syed).subtract(djed);
                    BigDecimal yyed1 = new BigDecimal(rs1.getString("ybx"));//实际报销金额
                    djed = new BigDecimal(rs2.getString("dj"));
                    yyed = yyed1.divide(wan, 4, BigDecimal.ROUND_HALF_UP);
                    djed = djed.divide(wan, 4, BigDecimal.ROUND_HALF_UP);
                    if (Double.parseDouble(String.valueOf(ze)) != 0.00) {
                        yszxl = yszxl = yyed1.divide(ze, 3, BigDecimal.ROUND_CEILING).multiply(bai).setScale(2);
                    }
                    //logger.info(ze + "=总额==" + syed + "=剩余额度==" + djed + "=冻结额度==" + yyed1 + "=已用额度==" + yszxl+",执行率:"+yszxl);
                    map[i].put("yyed", yyed.toString());
                    map[i].put("djed", djed.toString());
                    map[i].put("yszxl", yszxl.toString() + "%");
                    i++;
                    //获取项目核批渠道
                    String sql3 = "select  id,yslylx,je,syed,srlx,zcqd,dfczbkxm,zyczbksr,\n" +
                            "(select mc from uf_srysfl where id=zcqd)as zcqdmc,\n"+
                            "(select xmmc from uf_fzysrxm where id=dfczbkxm)as dfczbkxmmc \n" +
                            "from uf_jingfeilaiyuan where lcid="+requestId;
                    rs3.execute(sql3);
                    int qudaoIndex = 0;
                    int startRowindex = sheet.getLastRowNum()+1;
                    int endRowindex = startRowindex;

                    while (rs3.next()){
                        String zcqd = rs3.getString("zcqd");
                        String qdmc = rs3.getString("srlx").equals("0")
                                ?rs3.getString("yslylx")+"/"+tiaoZhengDao.getZyczbksrName(rs3.getString("zyczbksr"))
                                :rs3.getString("yslylx")+"/"+rs3.getString("zcqdmc")+ (zcqd.equals("5") || zcqd.equals("8")?"/"+rs3.getString("dfczbkxmmc"):"");
                        String yslylx =rs3.getString("yslylx");
                        String srlx = rs3.getString("srlx");
                        String dfczbkxm = rs3.getString("dfczbkxm");
                        String zyczbksr = rs3.getString("zyczbksr");
                        Double qdzcje = downDao.getSjbxjeV2(rs4,requestId,yslylx,srlx,zcqd,dfczbkxm,zyczbksr,edate);

                        HSSFRow dataRow  = sheet.createRow(sheet.getLastRowNum()+1);
                        dataRow.setHeightInPoints(23);
                        HSSFCell dataRow_c0 = dataRow.createCell(0);//序号
                        dataRow_c0.setCellStyle(dataRowStyle);
                        dataRow_c0.setCellValue(j+"");
                        HSSFCell dataRow_c1 = dataRow.createCell(1);//年度
                        dataRow_c1.setCellStyle(dataRowStyle);
                        dataRow_c1.setCellValue(mainTable.getString("ysnd"));
                        HSSFCell dataRow_c2 = dataRow.createCell(2);//申报单位
                        dataRow_c2.setCellStyle(dataRowStyle);
                        dataRow_c2.setCellValue(downDao.getSubCompanyNameById(mainTable.getString("sbdw")));
                        HSSFCell dataRow_c3 = dataRow.createCell(3);//所属独立核算单位
                        dataRow_c3.setCellStyle(dataRowStyle);
                        dataRow_c3.setCellValue(downDao.getSubCompanyNameById(mainTable.getString("dlhsdw")));
                        HSSFCell dataRow_c4 = dataRow.createCell(4);//项目名称
                        dataRow_c4.setCellStyle(dataRowStyle_o1);
                        dataRow_c4.setCellValue(mainTable.getString("xmmin")+"(是否追加:"+(sfwzjxm.isEmpty() || sfwzjxm.equals("0")?"否":"是")+")");
                        HSSFCell dataRow_c5 = dataRow.createCell(5);//预算核批数
                        dataRow_c5.setCellStyle(dataRowStyle);
                        dataRow_c5.setCellValue(yszje.toString());
                        HSSFCell dataRow_c6 = dataRow.createCell(6);//支出数
                        dataRow_c6.setCellStyle(dataRowStyle);
                        dataRow_c6.setCellValue(yyed.toString());
                        HSSFCell dataRow_c7 = dataRow.createCell(7);//冻结数
                        dataRow_c7.setCellStyle(dataRowStyle);
                        dataRow_c7.setCellValue(djed.toString());
                        HSSFCell dataRow_c8 = dataRow.createCell(8);//执行率
                        dataRow_c8.setCellStyle(dataRowStyle);
                        dataRow_c8.setCellValue(yszxl.toString() + "%");
                        HSSFCell dataRow_c9 = dataRow.createCell(9);//支出渠道
                        dataRow_c9.setCellStyle(dataRowStyle_o1);
                        dataRow_c9.setCellValue(qdmc);
                        HSSFCell dataRow_c10 = dataRow.createCell(10);//渠道核批金额
                        dataRow_c10.setCellStyle(dataRowStyle);
                        dataRow_c10.setCellValue(rs3.getString("je"));
                        HSSFCell dataRow_c111 = dataRow.createCell(11);//渠道支出金额
                        dataRow_c111.setCellStyle(dataRowStyle);
                        dataRow_c111.setCellValue(qdzcje);
                        qudaoIndex ++;
                        endRowindex++;
                    }
                    //如果核批数据>=2则合并其他表格行
                    if (qudaoIndex>=2){
                        CellRangeAddress reg0 = new CellRangeAddress(startRowindex, (endRowindex-1), 0, 0);
                        sheet.addMergedRegion(reg0);
                        CellRangeAddress reg1 = new CellRangeAddress(startRowindex, (endRowindex-1), 1, 1);
                        sheet.addMergedRegion(reg1);
                        CellRangeAddress reg2 = new CellRangeAddress(startRowindex, (endRowindex-1), 2, 2);
                        sheet.addMergedRegion(reg2);
                        CellRangeAddress reg3 = new CellRangeAddress(startRowindex, (endRowindex-1), 3, 3);
                        sheet.addMergedRegion(reg3);
                        CellRangeAddress reg4 = new CellRangeAddress(startRowindex, (endRowindex-1), 4, 4);
                        sheet.addMergedRegion(reg4);
                        CellRangeAddress reg5 = new CellRangeAddress(startRowindex, (endRowindex-1), 5, 5);
                        sheet.addMergedRegion(reg5);
                        CellRangeAddress reg6 = new CellRangeAddress(startRowindex, (endRowindex-1), 6, 6);
                        sheet.addMergedRegion(reg6);
                        CellRangeAddress reg7 = new CellRangeAddress(startRowindex, (endRowindex-1), 7, 7);
                        sheet.addMergedRegion(reg7);
                        CellRangeAddress reg8 = new CellRangeAddress(startRowindex, (endRowindex-1), 8, 8);
                        sheet.addMergedRegion(reg8);
                    }
                    j++;
                }
            }
            String filename = year+"各单位预算项目执行情况"+getTimestamp()+".xls";
            String rootPath = GCONST.getRootPath()+"log/gbhg/huangwm/";
            String path = rootPath + filename;
            File file = new File(path);
            workbook.write(file);//下载文件到服务器

        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("项目台账导出异常" + e.getMessage());
        }
    }

    /**
     * 获取当前日期时间。 YYYY-MM-DD HH:MM:SS
     * @return		当前日期时间
     */
    public static String getCurrDateTime() {
        Date newdate = new Date();
        long datetime = newdate.getTime();
        Timestamp timestamp = new Timestamp(datetime);
        return (timestamp.toString()).substring(0, 19);
    }
    /**
     * 获取时间戳   格式如：19990101235959
     * @return
     */
    private static String getTimestamp(){
        return getCurrDateTime().replace("-", "").replace(":", "").replace(" ", "");
    }
}
